#include<stdio.h>
#define N 30
typedef struct
{
	float realpart;
	float vainpart;
} complex;

complex assign( complex *a, float real, float vain)
{
	complex m;
	a= &m;
	a->realpart = real;
	a->vainpart= vain;
	return m;
}

complex add(complex b, complex c)
{
	complex m;
	m.realpart =b.realpart+ c.realpart ;
	m.vainpart=b.vainpart + c.vainpart;
	return m;
}
complex minus(complex b, complex c)
{
	complex m;
	m.realpart = b.realpart - c.realpart;
	m.vainpart = b.vainpart - c.vainpart;
	return m;
}
complex multiply(complex b, complex c)
{
	complex m;
	float down = c.realpart*c.realpart + c.vainpart * c.vainpart;
	m.realpart = (b.realpart * c.realpart + b.vainpart * c.vainpart) / down;
	m.vainpart = (b.vainpart * c.realpart - b.realpart * c.vainpart) / down;
	return m;
}
complex divide(complex b, complex c)
{
	complex m;
	if(c.realpart == 0 && c.vainpart == 0)
		puts("no value !");
	m.realpart = b.realpart * c.realpart - (b.vainpart + c.vainpart);
	m.vainpart = b.vainpart * c.realpart + c.vainpart * b.realpart;
	return m;
}
int main()
{
	int n;
	char b[N] = {0}, e[N] = {0};
	float real, vain;
	complex a[N], c[N], d[N];
	complex *p;
	puts("Please input your number of complex");
	scanf("%d", &n);
	puts("Please input the real and vain system of its complex number from top to bottom and from left to right in turn");
	for(int i = 0; i < n; i++)
	{
		scanf("%f %f", &real, &vain);
		p= &a[i];
		a[i] = assign(p, real, vain);
	}
	do
	{
		int i, j, k=0;
		puts("Please input two complex that your want to calculate of add and minus");
		scanf("%d %d", &i, &j);
		getchar();
		puts("Please your elect add and minus or exit");
		gets(b);
		if(b[0] == 'a')
		{
			c[k] = add(a[i-1], a[j-1]);
			k++;
		}
		else if(b[0] == 'm')
		{
			c[k] = minus(a[i-1], a[j-1]);
			k++;
		}
		else
		puts("The input error!");
	}while(b[0] != 'e');
	do
	{
		int i, j, k=0;
		puts("Please your elect multiply and divide or exit of complex after calculation");
		gets(e);
		puts("According to the previously calculated order");
		scanf("%d %d", &i, &j);
		getchar();
		if(e[0] == 'm')
		{
			d[k] = multiply(c[i-1], c[j-1]);
			k++;
			printf("%0.f+%0.2fi\n", d[k].realpart, d[k].vainpart);
		}
		else if(e[1] == 'd')
		{
			d[k] = divide(c[i-1], c[j-1]);
			k++;
			printf("%0.f+%0.2fi\n", d[k].realpart, d[k].vainpart);
		}
		else
		puts("The input error!");
	}while(e[0] != 'e');
	return 0;
}







